/**
 * Footballer - on/off-line
 */

if ( typeof is_online_timer == 'undefined' )
	var is_online_timer;
if ( typeof send_online_req_timer == 'undefined' )
	var send_online_req_timer;
if ( typeof is_online == 'undefined' )
	var is_online = 0;

$(document).ready(function(){
	//document.onkeypress = turnOnLine;
	//document.onclick = turnOnLine;
	//document.onmouseover = turnOnLine;
	//document.body.onunload = turnOffLine; //FF fail
	//window.onunload = turnOffLine;
});

function sendOnLineReq(id){
	if ( is_online ){
		$.post("/common/on_off_line_client.php", {clientid:id, act:"on"});
	}
	send_online_req_timer = setTimeout(function(){sendOnLineReq(id)}, 305000);
}

function turnOnLine(id){
	clearTimeout(is_online_timer);
	is_online_timer = setTimeout(function(){turnOffLine(id)}, 300000);
	if ( !is_online ){
		is_online = 1;
		sendOnLineReq(id);
	}
	is_online = 1;
}

function turnOffLine(id){
	if ( is_online ){
		$.post("/common/on_off_line_client.php", {clientid:id, act:"off"});
		is_online = 0;
	}
}
